package collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class CollectionInterfaceTest {
    public static void main(String[] args) {
        Collection<String> list = new ArrayList<>();
        list.add("张三");
        list.add("李四");
        list.add("王五");
        list.add("赵六");
        list.add("钱七");
        System.out.println("list.size() = " + list.size());
        System.out.println("list = " + list);
        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()) {
            String next = iterator.next();
            System.out.println("iterator.next() = " + next);
            if ("钱七".equals(next)) {
                iterator.remove();
            }
        }
        System.out.println("list = " + list);
        Collection<String> list1 = new ArrayList<>();
        list1.add("zhangsan");
        list1.add("lisi");
        list.addAll(list1);
        System.out.println("list = " + list);
        System.out.println("list.contains(\"zhangsan\") = " + list.contains("zhangsan"));
        list.remove("李四");
        System.out.println("list = " + list);
        System.out.println("list.isEmpty() = " + list.isEmpty());
        list.clear();
        System.out.println("list.isEmpty() = " + list.isEmpty());
        list.add("张三");
        String[] array = list.toArray(new String[0]);
        for (String s : array) {
            System.out.println("s = " + s);
        }
    }

}
